import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const routes = [{
    name: 'login',
    component: () => import('@/view/Login'),
    meta: {
      title: '登录'
    }
  },
  {
    name: 'home',
    component: () => import('@/view/Home'),
    meta: {
      title: '首页'
    }
  },
  {
    name: 'detail',
    component: () => import('@/view/Detail'),
    meta: {
      title: '详情'
    }
  },
  {
    name: 'about',
    component: () => import('@/view/About'),
    meta: {
      title: '关于'
    }
  },
  {
    name: 'address',
    component: () => import('@/view/Address'),
    meta: {
      title: '地址'
    }
  },
  {
    name: 'myReport',
    component: () => import('@/view/MyReport'),
    meta: {
      title: '我的绩效'
    }
  },
  {
    name: 'reportDetail',
    component: () => import('@/view/ReportDetail'),
    meta: {
      title: '绩效详情'
    }
  },
  {
    name: 'formTest',
    component: () => import('@/view/FormTest'),
    meta: {
      title: '表单组件'
    }
  }
]

routes.forEach(route => {
  route.path = route.path || '/' + (route.name || '')
})

const router = new Router({
  routes
})

router.beforeEach((to, from, next) => {
  const title = to.meta && to.meta.title
  if (title) {
    document.title = title
  }
  next()
})

export default router